package org.NooLab.texx.storage;

import java.sql.Connection;

import org.NooLab.utilities.files.DFutils;


import org.NooLab.itexx.storage.docserver.storage.DocoDataBaseIntf;
import org.NooLab.texx.properties.TexxProperties;


import com.iciql.Db;

/* the type org.NooLab.itexx.storage.ConnectorClientIntf cannot be resolved. 
 * It is indirectly referenced from required .class files
 * 
 * import org.NooLab.itexx.storage.ConnectorClientIntf;
 * 
 */


public class DocObsDataBase  {

	DocoDataBaseIntf docoDataBase;
	Db iciDb ;
	public Connection connection;
	TexxProperties texxProperties;
	
	String docoDataBaseFolder="";
	// private DocumentObserverProperties docoProperties;
	// private DocoPropertiesHandler docoPropertiesDefaults;
	
	// ========================================================================
	public DocObsDataBase(TexxProperties props) throws Exception{
		 
		docoDataBase = new DocoDataBase(props);
		
		/*
		IniProperties.fluidSomProjectBasePath = ...
		DocoServStartup.setApplicationID("DocServ");
		
		docoProperties = DocumentObserverProperties.getInstance( "" );
		
		docoPropertiesDefaults = new DocoPropertiesHandler(docoProperties);
		docoPropertiesDefaults.setInstance( "doco" ,0 );
		
		String prj = DocoServStartup.getLastProjectName();
		
		String src =  IniProperties.dataSource;
		src = DocoServStartup.getLastDataSet() ;
		
		docoPropertiesDefaults.setConfigFile(src );
		//explicitlySettingProperties();
		
		DocoControlProperties dc = docoProperties.getControlProperties();
		dc. readSettings("");
		*/
		
		texxProperties = props;
		
	}
	// ========================================================================
	
	
	public boolean databaseIsRunningAsServer() throws Exception{
		boolean rB=false;
		String dir="";
		
		
		dir = docoDataBase.getStorageDir();
		
		if (DFutils.folderExists(dir)==false){
			docoDataBase.setStorageFolder( dir );
		}
		
		connection = docoDataBase.getWireLessDatabaseServer("TEXX","texx") ;
		docoDataBase.open(connection);
		iciDb = docoDataBase.getIciDb() ;
		rB= ((connection!=null) && (iciDb!=null));
	
		// proceed only if the user "TEXX" exists...
		
		return rB;
	}


	public DocoDataBaseIntf getDocoDataBase() {
		return docoDataBase;
	}


	public Db getIciDb() {
		return iciDb;
	}


	public Connection getConnection() {
		return connection;
	}


	public TexxProperties getTexxProperties() {
		return texxProperties;
	}
	
	
}
